package com.example.flshtarvel.service;

import com.example.flshtarvel.entity.RouteCollectMap;
import com.example.flshtarvel.mapper.RouteCollectMapMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RouteCollectMapService {
    @Autowired(required = false)
    RouteCollectMapMapper routeCollectMapMapper;

    //路线点赞
    public int routeCollect(String routeId, String userId){
        List<RouteCollectMap> routeCollectMaps = routeCollectMapMapper.selectRouteCollectByRouteIdAndUserId(routeId,userId);
        if(routeCollectMaps.size()==0 || routeCollectMaps==null){
            int result = routeCollectMapMapper.routeCollect(routeId,userId);
            return result;
        }else{
            return 0;
        }
    }

    //取消点赞
    public int deleteRouteCollect(String routeId,String userId){
        int result = routeCollectMapMapper.deleteRouteCollect(routeId,userId);
        return result;
    }

    //查询点赞    根据路线id 用户id
    public int selectRouteCollectByRouteIdAndUserId(String routeId, String userId){
        List<RouteCollectMap> routeCollectMaps = routeCollectMapMapper.selectRouteCollectByRouteIdAndUserId(routeId,userId);
        int result;
        if(routeCollectMaps.size()==0||routeCollectMaps==null){
            result=0;
        }else{
            result=1;
        }
        return result;
    }

    //查询点赞数    根据路线id
    public int selectRouteCollectByRouteId(String routeId){
        int result = routeCollectMapMapper.selectRouteCollectByRouteId(routeId);
        return result;
    }
}
